import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import approval from './modules/approval'
import attendance from './modules/attendance'
import department from './modules/department'
import employee from './modules/employee'
import role from './modules/role'
import salary from './modules/salary'
import social from './modules/social'
import permission from './modules/permission'
import newPage from './modules/newPage'

Vue.use(Router)

// 拆分路由
// 动态路由
export const routerSpace = [
  department,
  role,

  employee,
  permission,
  attendance,
  approval,
  salary,
  social,
  newPage

]

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    // hidden: true,
    component: () => import('@/views/login')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard'),
        meta: {
          title: '首页',
          icon: 'dashboard'
        }
      }
    ]

  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }

  // 404 page must be placed at the end !!!

]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()
// 动态加回路由
// router.addRoutes(routerSpace)

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
